//int totalRooms = 10;

#include "bitmap_image.hpp"
#include "Map.h"
#include "GlobalDefine.h"

using namespace std;

unsigned int border = 20;
unsigned int tile = 50;
unsigned int spacing = 10;
bitmap_image map_bitmap;

int main();
void printMapCLI(int [tot*2][tot*2]);
void printMapGFX(int [tot*2][tot*2]);
void roomLayout(int,int);

int main() {
	int seed = time(NULL);
	std::cout << "Enter a seed to generate the game:" << std::endl;
	std::cin >> seed;
	srand(seed);

	Map ourMap = Map();
	
	std::cout << "\n\n";

	printMapCLI(ourMap.mapArray);
	printMapGFX(ourMap.mapArray);
	for (int a = 1; a < 11; a = a + 1)
	{
		roomLayout(a,seed);
		//cout << "value of a: " << a << endl;
	}
	system("pause");
	exit(0);
}

void printMapCLI(int table[tot*2][tot*2]) {

	for (int r = 0; r < tot*2; r++) {
		for (int c = 0; c < tot*2; c++) {
			cout << table[r][c];
			cout << " ";
		}
		cout << "\n";
	}

	cout << "\n";

	return;
}

void printMapGFX(int table[tot * 2][tot * 2]) {

	unsigned int height = (2 * border) + (tot*2*tile) + ((tot*2) - 1)*spacing;
	unsigned int width = (2 * border) + (tot*2*tile) + ((tot*2) - 1)*spacing;

	map_bitmap = bitmap_image(width, height);
	map_bitmap.set_all_channels(0, 0, 0);

	for (int curr_row = 0; curr_row < tot*2; curr_row++) {
		for (int curr_col = 0; curr_col < tot*2; curr_col++) {
			int x1 = border + (curr_col*tile) + (curr_col*spacing);;
			int x2 = border + ((curr_col + 1)*tile) + (curr_col*spacing);
			int y1 = border + (curr_row*tile) + (curr_row*spacing);
			int y2 = border + ((curr_row + 1)*tile) + (curr_row*spacing);

			if (table[curr_row][curr_col] != 0) {
				for (int x = x1; x <= x2; x++) {
					for (int y = y1; y <= y2; y++) {
						map_bitmap.set_pixel(x, y, 255, 255, 255);
					}
				}
			}
		}
	}

	map_bitmap.save_image("output.bmp");
}

void roomLayout(int room, int seed) {
	srand(room*seed);
	int enemy1 = 0;
	int enemy2 = 0;
	int enemy3 = 0;
	int enemy4 = 0;
	int item1 = 0;
	int item2 = 0;
	int item3 = 0;
	int item4 = 0;
	std::cout << "Layout for room " << room << ":" << std::endl;
	enemy1 = rand() % 100;
	enemy2 = rand() % 100;
	enemy3 = rand() % 100;
	enemy4 = rand() % 100;
	item1 = rand() % 100;
	item2 = rand() % 100;
	item3 = rand() % 100;
	item4 = rand() % 100;
	std::cout << "Enemies" << std::endl;
	std::cout << enemy1 << std::endl;
	std::cout << enemy2 << std::endl;
	std::cout << enemy3 << std::endl;
	std::cout << enemy4 << std::endl;
	std::cout << "Items" << std::endl;
	std::cout << item1 << std::endl;
	std::cout << item2 << std::endl;
	std::cout << item3 << std::endl;
	std::cout << item4 << std::endl;
	std::cout << std::endl;
	
	

}